<template>
  <div class="wechat-platform-add">
    <info v-show="showTab === 'one'" @cancel="cancelType" @next="nextStep" :todoType="'add'"></info>
    <step v-show="showTab === 'two'" @cancel="cancelType" @next="nextStep" :formData="formData" :wechatUrl="wechatUrl" :todoType="'add'"></step>
  </div>
</template>
<script>
  import step from './wechatPlatformStep.vue'
  import info from './wechatPlatformInfo.vue'
  import {deepClone} from '@/utils/m7Utils'
  export default {
    name: 'wechatPlatformAdd',
    data () {
      return {
        showTab: 'one',
        formData: {}
      }
    },
    components: {
      info,
      step
    },
    methods: {
      cancelType (step) {
        if (step === 1) {
          this.$emit('cancel')
        } else if (step === 2) {
          this.showTab = 'one'
        }
      },
      nextStep (data) {
        if (data.step === 1) {
          this.formData = deepClone(data.data)
          this.wechatUrl = deepClone(data.wechatUrl)
          this.showTab = 'two'
        } else if (data.step === 2) {
          this.$store.dispatch('saveWxDevModeConfig', this.formData).then((res) => {
            if (res.success) {
              this.$message.success(this.$t('configLazyLoad.channel.addSuccess'))
              this.$emit('cancel')
            }
          })
        }
      }
    },
    mounted () {
      this.showTab = 'one'
    }
  }
</script>
<style lang="stylus" scoped>
  @import "../../../../../assets/common.styl"
  .wechat-platform-add
    height calc(100vh - 170px)
    overflow auto
  .new-config
    .wechat-platform-add
      height calc(100vh - 52px)
</style>
